// pages/gongxiu/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
   gongke:'念佛',
   qun:'大众共修',
   date:'今天',
   page:'1',
   hiddenshowyiguanzhu: false,
   hiddenshowweiguanzhu:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
   
    
    /*
    that.setData({
      gongke:gongke
    })
    */
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    console.log(app)
    if(app.globalData.gongke){
      var gongke = app.globalData.gongke
    }else{
      var gongke = this.data.gongke
    }
    console.log(gongke)
    if (app.globalData.qun) {
      var qun = app.globalData.qun
    } else {
      var qun = this.data.qun
    }
    console.log(qun)
    if (app.globalData.date) {
      var date = app.globalData.date
      console.log('1')
    } else {
      var date = this.data.date
    }
    console.log(date)
    var page = this.data.page;
    console.log(page)
    
   
    wx.request({
      url: 'https://api.bjlya.com.cn/nfq.php/index/Gongxiu/index', // 仅为示例，并非真实的接口地址
      data: {
        openid: app.openid,
        qun:qun,
        gongke:gongke,
        date:date,
        page:page,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
        that.setData({
          qun_men:res.data.qun_men,
          yiguanzhu: res.data.yiguanzhu,  //已关注的
          weiguanzhu: res.data.weiguanzhu,  //没有关注的
          hiddenshowyiguanzhu: res.data.hiddenshowyiguanzhu,
          hiddenshowweiguanzhu: res.data.hiddenshowweiguanzhu,
          note:res.data.note,
          qun:qun,
          gongke:gongke,
          date:date,
        })
        app.globalData.gongke = null
        app.globalData.qun = null
        app.globalData.date =null
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 去选择页面
   */
  onposttap: function (e) {
    wx.navigateTo({
      url: "../gongxiu/item/index"
    })
  },

  onPostTap1: function (event) {
    wx.navigateTo({
      url: "../gongxiu/select/index"
    })

  },
  geren_guanzhu:function(event){
    var that = this
    var guanzhu_openid = event.currentTarget.dataset.openid;
    var guanzhu_nickname = event.currentTarget.dataset.nickname;
    var openid = app.openid
    //  console.log(guanzhu_nickname+guanzhu_openid)
    wx.request({
      url: 'https://api.bjlya.com.cn/nfq.php/index/Gongxiu/index5', // 仅为示例，并非真实的接口地址
      data: {
        guanzhu_nickname:guanzhu_nickname,
        guanzhu_openid:guanzhu_openid,
        openid:openid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data)
        that.onLoad();
        that.onShow();
      }
    })

  },
  geren_guanzhu_quxiao:function(event){
    var that = this
    var guanzhu_openid = event.currentTarget.dataset.openid;
    var guanzhu_nickname = event.currentTarget.dataset.nickname;
    console.log(guanzhu_openid+guanzhu_nickname)
    wx.showModal({
      title: '提示',
      content: '您确定取消对 "'+guanzhu_nickname+'" 的关注吗',
      success(res) {
        if (res.confirm) {
          //console.log('用户点击确定 取消关注 ')
          wx.request({
            url: 'https://api.bjlya.com.cn/nfq.php/index/Gongxiu/index6', // 仅为示例，并非真实的接口地址
            data: {
              openid:app.openid,
              guanzhu_openid:guanzhu_openid,
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success(res) {
              console.log(res.data)
              that.onLoad();
              that.onShow();
            }
          })


         //上面完成request
        }
        //上面 完成if 判断
         else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  beizhuname: function (e) {
    // console.log(e.currentTarget.dataset.openid + e.currentTarget.dataset.nickname + app.openid);
    var beizhuopenid = e.currentTarget.dataset.openid;
    var beizhunickname = e.currentTarget.dataset.nickname;
    var beizhuurl = e.currentTarget.dataset.src;
    // console.log(beizhuurl)
    wx.navigateTo({
      url: '/pages/gongxiu/beizhuname/index' + '?beizhuopenid=' + beizhuopenid + '&beizhunickname=' + beizhunickname + '&beizhuurl=' +beizhuurl
    })
  },
  onReachBottom: function () {
    var that = this;
    // 显示加载图标
    wx.showLoading({
      title: '玩命加载中',
    })
    // 页数+1
    var page = Number(that.data.page)
    that.data.page = page + 1;
    console.log('收到'+that.data.page);
    wx.request({
      url: 'https://api.bjlya.com.cn/nfq.php/index/Gongxiu/index/?page=' + that.data.page + '&openid=' + app.openid + '&qun=' + that.data.qun + '&gongke=' + that.data.gongke + '&date=' + that.data.date,
      method: "GET",
      // 请求头部
      header: {
        'content-type': 'application/text'
      },
      success: function (res) {
        // 回调函数
        console.log(res.data);

        //上面 for 结束
        // 设置数据
        that.setData({
          weiguanzhu: res.data.weiguanzhu,  //没有关注的
        })
        // 隐藏加载框
        wx.hideLoading();
      }
      //上面 success 结束
    })
    //上面 request 结束

  },
  backpage:function(){
    var that = this;
    // console.log('page')
    that.setData({
     page:1
    })
    that.onLoad();
    that.onShow();
  },
 

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})